#pragma once

#include <cstddef>
#include <atomic>

namespace stream {
namespace meta {

class Size {
	static Size __size;
public:
	static Size & empty(){
		return __size;
	}
	Size(size_t v = 0) {
		_v.store(v);
	}
	virtual ~Size(){}

	//load from persist
	virtual bool load();

	//store to persist
	virtual bool store();

	//atomic && only memory
	inline size_t get() const{
		return _v.load();
	}

	//atomic && only memory
	inline void set(size_t sz){
		_v.store(sz);
	}

	//atomic && only memory && return old_v
	inline size_t inc(size_t step = 1){
		return _v.fetch_add(step);
	}

	//atomic && only memory && return old_v
	inline size_t dec(size_t step = 1){
		return _v.fetch_sub(step);
	}
private:
	std::atomic<size_t> _v;
};

}//end namespace meta
}//end namespace stream

